//购物车小仓库
import request from '../../api/request.js'

const state = {
	cart_list: []
}

const actions = {
	// 获取购物车列表
	async get_cart_list(context) {
		let res = await request({
			url: '/member/cart',
			method: 'get',
			headers: {
				Authorization: localStorage.getItem('token')
			}
		})
		context.commit('GET_CART_LIST', res.result)
	},
	// 加入购物车
	async add_cart(context, item) {
		let res = await request({
			url: '/member/cart',
			method: 'post',
			headers: {
				Authorization: localStorage.getItem('token'),
				"User-Agent":"Apifox/1.0.0 (https://apifox.com)",
				"Content-Type":"application/json"

			},
			data: {
				
					"skuId": item.sku.id,
					"count": item.num
				
			}
		})
		console.log(res.result)
	},
	// 删除/清空购物车
  async	delete_cart(context,ids){
	    let res=await request({
			url:'/member/cart',
			method:'delete',
			headers:{
				Authorization:localStorage.getItem('token'),
				
				"Content-Type":"application/json"
			},
			data:{
				
					ids:ids
				
			}
		})
			console.log(res.result)
		
		
	}
}

const mutations = {
	GET_CART_LIST(state, data) {
		state.cart_list = data || []
	}
}

const getters = {

}

export default {

	namespaced: true,
	state,
	actions,
	mutations,
	getters
}